<!DOCTYPE html>
<html style="width:100%;height:100%;">
<head lang="en">
    <meta charset="UTF-8">
    <title>微信平台列表</title>
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/default/easyui.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/color.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/icon.css">
    <link type="text/css" rel="stylesheet" href="/resources/css/yidong.css">
    <script type="text/javascript" src="/resources/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/resources/easyui/plugin/jquery.cookie.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var pageSize = $.cookie("pageSize");
            var pageNumber = $.cookie("pageNumber");
            if(!pageSize) {
                $.cookie("pageSize", 10, {expires:1});
            }
            if(!pageNumber) {
                $.cookie("pageNumber", 1, {expires:1});
            }
            loadAppSecretList($.cookie("pageSize"), $.cookie("pageNumber"));
            var pager = $('#appsecretList').datagrid('getPager');
            if(pager){
                $(pager).pagination({
                    onSelectPage:function(pageNumber, pageSize){
                        $.cookie("pageNumber", pageNumber, {expires:1});
                        loadAppSecretList(pageSize, pageNumber);
                    },
                    onRefresh:function(pageNumber, pageSize){
                        $.cookie("pageNumber", pageNumber, {expires:1});
                        loadAppSecretList(pageSize, pageNumber);
                    },
                    onChangePageSize:function(pageSize){
                        $.cookie("pageSize", pageSize, {expires:1});
                        loadAppSecretList(pageSize, 1);
                    }
                })
            }
        });

        function loadAppSecretList(pageSize, pageNo, successFun){
            restClient('/rest/appsecret/listByPage', function(data){
                $('#appsecretList').datagrid('loadData',data);
                if(successFun) successFun();
            }, {pageSize:pageSize, pageNo:pageNo});
        }
    </script>
</head>
<body onload="isLogon();" style="width:100%;height:100%;margin: 0;">
<table id="appsecretList" class="easyui-datagrid" style="width:100%;height:100%;"
       toolbar="#toolbar" pagination="true"
       data-options="pageList:[10,15,20],pageSize:$.cookie('pageSize') ? $.cookie('pageSize') : 10"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="appId" width="50">AppId</th>
        <th field="appSecret" width="100">AppSecret</th>
        <th field="cityId" width="50" data-options="formatter:formatCity">城市</th>
        <th field="description" width="100">描述</th>
        <th field="oldCount" width="30">原始粉丝数</th>
        <th field="status" width="20" data-options="formatter:formatStatus">状态</th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newOne()">新建</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editOne()">编辑</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyOne()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:auto;padding:-20px"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post">
        <div class="fitem">
            <label>AppId：</label>
            <input id="appId" name="appId" class="easyui-textbox easyui-validatebox"
                   required="true" data-options="missingMessage:'该输入项为必输项'">
        </div>
        <div class="fitem">
            <label>AppSecret：</label>
            <input id="appSecret" name="appSecret" class="easyui-textbox easyui-validatebox"
                   required="true" data-options="missingMessage:'该输入项为必输项'">
        </div>
        <div class="fitem">
            <label>城市：</label>
            <input id="cityId" name="cityId" class="easyui-combobox easyui-validatebox"
                   data-options="valueField:'id', textField:'name', editable:false" required="true">
        </div>
        <div class="fitem">
            <label>描述：</label>
            <input id="description" name="description" class="easyui-textbox">
        </div>
        <div class="fitem">
            <label>原始粉丝数：</label>
            <input id="oldCount" name="oldCount" class="easyui-textbox">
        </div>
        <div class="fitem">
            <label>状态：</label>
            <select id="status" name="status" class="easyui-combobox easyui-validatebox" data-options="editable:false" required="true">
                <option value="0">启用</option>
                <option value="-1">禁用</option>
                <option value="-2">删除</option>
            </select>
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveOne()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>

<script type="text/javascript">
    var url;
    var successMsg;
    function newOne(){
        $('#dlg').dialog('open').dialog('setTitle','新建');
        $('#fm').form('clear');
        loadCityCombobox($('#cityId'), true);
        $('#status').combobox('setValue', 0);
        url = '/rest/appsecret/create';
        successMsg = "添加成功";
    }
    function editOne(){
        var row = $('#appsecretList').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('setTitle', '编辑');
            loadCityCombobox($('#cityId'));
            $('#fm').form('load',row);
            url = '/rest/appsecret/update/'+row.id;
            successMsg = "编辑成功";
        }
    }
    function saveOne(){
        restClient(url, function (result) {
            if (result.success) {
                $('#dlg').dialog('close');
                loadAppSecretList($.cookie("pageSize"), $.cookie("pageNumber"), function () {
                    $.messager.show({
                        title: '温馨提醒',
                        msg: successMsg
                    });
                });
            } else {
                $.messager.show({
                    title: '温馨提醒',
                    msg: result.msg ? result.msg : result.message
                });
            }
        }, $('#fm').serialize());
    }
    function destroyOne(){
        var row = $('#appsecretList').datagrid('getSelected');
        if (row){
            $.messager.confirm('确认','确认要删除【'+row.appId+'】么?',function(r){
                if (r){
                    restClient('/rest/appsecret/delete/'+row.id, function(result){
                        if (result.success){
                            loadAppSecretList($.cookie("pageSize"), $.cookie("pageNumber"), function(){
                                $.messager.show({
                                    title: '温馨提醒',
                                    msg: '删除成功'
                                });
                            });
                        } else {
                            $.messager.show({
                                title: '温馨提醒',
                                msg: result.msg ? result.msg : result.message
                            });
                        }
                    });
                }
            });
        }
    }
</script>
</body>
</html>